package com.gjy.learning.scala

import java.sql.{Connection, DriverManager, Statement}

object OracleTableCreator {
  def main(args: Array[String]): Unit = {
    val url = "jdbc:oracle:thin:@localhost:1521:ORCL"
    val username = "SCOTT"
    val password = "123456"

    // 加载Oracle JDBC驱动
    Class.forName("oracle.jdbc.driver.OracleDriver")

    // 获取数据库连接
    val connection: Connection = DriverManager.getConnection(url, username, password)
    try {
      val statement: Statement = connection.createStatement()

      // 创建表的SQL语句
      val createTableSql =
        """
          |CREATE TABLE employees_test (
          |    id NUMBER(10) PRIMARY KEY,
          |    name VARCHAR2(100),
          |    salary NUMBER(10, 2)
          |)
          |""".stripMargin

      // 执行SQL语句创建表
      statement.executeUpdate(createTableSql)
      println("Table 'employees' created successfully.")
    } catch {
      case e: Exception => e.printStackTrace()
    } finally {
      // 关闭数据库连接
      connection.close()
    }
  }
}
